import axios from 'axios'
import { ElMessage } from 'element-plus';
function addFood(food:food,token:string){

var data = JSON.stringify({
   "name": food.name,
   "price": food.price,
   "business": food.business,
   "url": food.url,
   "text":food.text
});

var config = {
   method: 'post',
   url: 'http://wm.tocode.store/cai/shop/addCai',
   headers: { 
      'token': token, 
      'Content-Type': 'application/json'
   },
   data : data
};
axios(config)
.then(function (response:any) {
   console.log(JSON.stringify(response.data));
   ElMessage({
      message: '添加成功！',
      type: 'success',
    })
})
.catch(function (error:any) {
   console.log(error);
});
}
function delfood(foodname:string,shopname:string,token:string){
   return new Promise<void>((resolve, reject)=>{
      var config = {
         method: 'delete',
         url: 'http://wm.tocode.store/cai?shopname='+shopname+'&name='+foodname,
         headers: { 
            'token': token, 
         }
      };
      
      axios(config)
      .then(function (response) {
         console.log(JSON.stringify(response.data));
         ElMessage({
            message: '删除成功！',
            type: 'success',
          })
          resolve()
      })
      .catch(function (error) {
         console.log(error);
         reject()
      });
   })
  
   

}
export{
   addFood,delfood
}